<?php

namespace app\common\model\record;

use think\Model;

class RecordCheckWork extends Model 
{ 
    protected $name = 'record_check_work'; 

    protected $schema = [
        'id'             => 'int', //考勤记录表
        'uid'             => 'int', //用户ID
        'day'             => 'date', //日期
        'start_time'             => 'datetime', //打卡开始时间
        'end_time'             => 'datetime', //打卡结束时间
        'is_overtime'             => 'tinyint', //是否加班
        'is_late'             => 'tinyint', //是否迟到
        'is_leave_early'             => 'tinyint', //是否早退
        'is_absence_duty'             => 'tinyint', //是否缺勤
        'create_time'             => 'datetime', //创建时间
        'remark'             => 'text', //备注
        'reserve_start_time'             => 'datetime', //设定打卡开始时间
        'reserve_end_time'             => 'datetime', //设定打卡结束时间
        'vacation_id'             => 'int', //请休假ID
        'completion_task_id'             => 'int', //出差ID
        'supply_card_id'             => 'varchar', //补卡ID
        'check_work_type'             => 'tinyint', //[select] 【1-正常班|2-加班】
        'reward_punishment_type'             => 'tinyint', //[select]  【1-奖励|2-扣款】
        'price'             => 'decimal', //金额
        'admin_name'             => 'varchar', //操作者
        'update_time'             => 'datetime', //更新时间
        'status'             => 'tinyint', //-1 删除 0默认 1正常
    ];

    //处理数据模型 
    public static function fillModels($models){ 
        $list = []; 
        foreach ($models as $model) { 
            $listItem = static::fillModel($model); 
            $list[] = $listItem; 
        } 
        return $list; 
    } 

    public static function fillModel($model){ 
        $data = [];
        $data['id'] = $model['id'];
        $data['uid'] = $model['uid'];
        $data['day'] = $model['day'];
        $data['start_time'] = $model['start_time'];
        $data['end_time'] = $model['end_time'];
        $data['is_overtime'] = $model['is_overtime'];
        $data['is_late'] = $model['is_late'];
        $data['is_leave_early'] = $model['is_leave_early'];
        $data['is_absence_duty'] = $model['is_absence_duty'];
        $data['create_time'] = $model['create_time'];
        $data['remark'] = $model['remark'];
        $data['reserve_start_time'] = $model['reserve_start_time'];
        $data['reserve_end_time'] = $model['reserve_end_time'];
        $data['vacation_id'] = $model['vacation_id'];
        $data['completion_task_id'] = $model['completion_task_id'];
        $data['supply_card_id'] = $model['supply_card_id'];
        $data['check_work_type'] = (string)$model['check_work_type'];
        $data['check_work_type_name'] = self::getCheckWorkTypeName($model['check_work_type']);
        $data['reward_punishment_type'] = (string)$model['reward_punishment_type'];
        $data['reward_punishment_type_name'] = self::getRewardPunishmentTypeName($model['reward_punishment_type']);
        $data['price'] = $model['price'];
        $data['admin_name'] = $model['admin_name'];
        $data['update_time'] = $model['update_time'];
        $data['status'] = (string)$model['status'];
        return $data;
    } 

    /** 
     *【方法注释】处理[select] 【1-正常班|2-加班】
     *@param $value 传入的值
     *@param string 返回的值
     */
    public static function getCheckWorkTypeName($value){
        $arr = [
            1=>"正常班",
            2=>"加班",
        ];
        return $arr[$value];
    } 

    /** 
     *【方法注释】处理[select]  【1-奖励|2-扣款】
     *@param $value 传入的值
     *@param string 返回的值
     */
    public static function getRewardPunishmentTypeName($value){
        $arr = [
            1=>"奖励",
            2=>"扣款",
        ];
        return $arr[$value];
    } 

    /** 
     *【方法注释】获取数据列表 
     *@param $where 查询的条件数组
     *@param $limit_start 获取数据，从第$limit_start条数据开始
     *@param $page_size 获取数据，从第$limit_start条数据开始，取$page_size条数据
     *@param array 返回的数据，数组
     */
    public static function getList($where, $limit_start, $page_size){
        $lists =  self::where($where)->order('id','desc')->limit($limit_start,$page_size)->select();
        return self::fillModels($lists);
    } 

    /** 
     *【方法注释】获取数据条数 
     *@param $where 查询的条件数组
     *@param int 返回的数据条数
     */
    public static function getCount($where){
        return self::where($where)->count();
    } 

    /** 
     *【方法注释】获取单条数据 
     *@param $where 查询的条件数组
     *@param array 返回的单条数据
     */
    public static function getOne($where){
        return self::fillModel(self::where($where)->find());
    } 

} 
